﻿Imports System.Xml

Public Class XmlTools
    Public Shared Function ReadUser(ByVal Node As XmlNode) As User
        Dim o_User As User = Nothing
        If Node IsNot Nothing Then
            o_User = New User
            With o_User
                o_User.uri = XmlTools.GetXmlString(Node, "uri")
                o_User.permalink = XmlTools.GetXmlString(Node, "permalink")
                o_User.permalinkurl = XmlTools.GetXmlString(Node, "permalink-url")
                o_User.username = XmlTools.GetXmlString(Node, "username")
            End With
        End If
        Return o_User
    End Function
    Public Shared Function GetXmlPublicPrivate(ByVal Node As XmlNode, ByVal Field As String) As Track.TrackVisability
        If Node.Item(Field) IsNot Nothing Then
            If Node.Item(Field).InnerText IsNot Nothing Then
                If Node.Item(Field).InnerText.ToUpper = "PUBLIC" Then
                    Return Track.TrackVisability.Public
                Else
                    Return Track.TrackVisability.Private

                End If
            End If
        End If
        Return Nothing
    End Function
    Public Shared Function GetXmlDate(ByVal Node As XmlNode, ByVal Field As String) As Date
        If Node.Item(Field) IsNot Nothing Then
            If Node.Item(Field).InnerText IsNot Nothing Then
                Return CDate(Node.Item(Field).InnerText)
            End If
        End If
        Return Nothing
    End Function
    Public Shared Function GetXmlSingle(ByVal Node As XmlNode, ByVal Field As String) As Single
        If Node.Item(Field) IsNot Nothing Then
            If Node.Item(Field).InnerText IsNot Nothing Then
                Return Val(Node.Item(Field).InnerText)
            End If
        End If
        Return Nothing
    End Function
    Public Shared Function GetXmlString(ByVal Node As XmlNode, ByVal Field As String) As String
        If Node.Item(Field) IsNot Nothing Then
            If Node.Item(Field).InnerText IsNot Nothing Then
                Return CStr(Node.Item(Field).InnerText)
            End If
        End If
        Return Nothing
    End Function
    Public Shared Function GetXmlBooloean(ByVal Node As XmlNode, ByVal Field As String) As Boolean
        If Node.Item(Field) IsNot Nothing Then
            If Node.Item(Field).InnerText IsNot Nothing Then
                Return CBool(Node.Item(Field).InnerText)
            End If
        End If
        Return Nothing
    End Function
End Class
